﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace WEALTH.Manager.User
{
    public partial class ModifyPassword : BasePage
    {
        private UserFilter userFilter = new UserFilter();
        private ExcuteDao userManage = new ExcuteDao();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["checkPwd"]))
            { //密码验证
                string inputPwd = Request["password"];
                if (!string.IsNullOrEmpty(inputPwd))
                {
                    try
                    {
                        DataSet dataset = userManage.Get_LoginUser(this.getCurrentUser().UserID, AppFunction.Encrypt(inputPwd));
                        if (dataset != null && dataset.Tables[0].Rows.Count > 0)
                        {
                            Response.Write(0);
                            Response.End();
                            return;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                Response.Write(-1);
                Response.End();
            }
        }
        /// <summary>
        /// 修改密码 存入数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            this.userFilter.User_ID = this.getCurrentUser().UserID;
            this.userFilter.User_pwd = AppFunction.Encrypt(SpecialCharHandler.toHTMLJSString(this.txtNewPwd.Text));
            if (userManage.Update_User_Pwd(this.userFilter) != 0)
            {
                ClientScript.RegisterStartupScript(GetType(), "message", "<script>jBox.tip('密码修改成功.');parent.CloseCurrentBox();</script>");
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "message", "<script>jBox.tip('密码修改失败!');parent.CloseCurrentBox();</script>");
            }
        }
    }
}